import { ref, computed, reactive } from 'vue'
import { defineStore } from 'pinia'
import { getUserInfo } from '@/api/account';

type TUserInfo = {
  hasLogined: boolean;
}
export const useUserStore = defineStore('user', () => {
  const user = reactive<any>({
    hasLogined: false
  })

  function updateUserInfo(params: any = {}) {
    getUserInfo(params)
    .then((data: any) => {
      if (data) {
        Object.assign(user, data, {
          hasLogined: true
        });
      } else {
        user.hasLogined = false;
      }
    }).catch(() => {
      user.hasLogined = false;
    });
  }

  return { user, updateUserInfo }
})
